﻿using System;
using System.Collections.Generic;
using WindowsForms.AOnline.Presenter.Dictionary.AutoBusiness;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlAutoBusinessList : BaseListUserControl, IAutoBusinesssView  
    {
        private readonly AutoBusinesssPresenter _autoBusinesssPresenter; 

        public UserControlAutoBusinessList()
        {
            InitializeComponent();
            _autoBusinesssPresenter = new AutoBusinesssPresenter(this);
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteGrid()
        {
            return new AutoBusinessPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }

        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoGrid(int page)
        {
            TotalPage = _autoBusinesssPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _autoBusinesssPresenter.Display(page);
            }
        }

        public IList<Model.BusinessObjects.Dictionary.AutoBusinessModel> AutoBusinesss
        {
            set
            {
                grdList.DataSource = value;
                
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AutoBusinessId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Description", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AutoBusinessCode", ColumnCaption = "Mã định khoản", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AutoBusinessName", ColumnCaption = "Tên định khoản", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 200 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "RefTypeId", ColumnCaption = "Loại CT", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 200 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "VoucherTypeId", ColumnCaption = "Nghiệp vụ", ColumnPosition = 4, ColumnVisible = true, ColumnWith = 200 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DebitAccountNumber", ColumnCaption = "Tài khoản nợ", ColumnPosition = 5, ColumnVisible = true, ColumnWith = 150 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "CreditAccountNumber", ColumnCaption = "Tài khoản có", ColumnPosition = 6, ColumnVisible = true, ColumnWith = 150 });
            }
        }
    }
}
